from sqlalchemy import Column, Integer, String, Boolean
from sqlalchemy.orm import relationship

from .session import Session
from .student import Student
from .counselor import Counselor
from ..db.base import Base, TimestampMixin

class User(Base, TimestampMixin):
    """用户数据库模型"""
    __tablename__ = "users"

    id = Column(Integer, primary_key=True, index=True)
    account_id = Column(Integer, unique=True, index=True, nullable=True)
    name = Column(String, nullable=False)
    email = Column(String, unique=True, index=True, nullable=False)
    phone_number = Column(String, unique=True, nullable=False)
    hashed_password = Column(String, nullable=False)
    role = Column(String, nullable=False)  # "student", "counselor" 或 "admin"
    is_active = Column(Boolean, default=True)

    # 关系
    student = relationship("Student", back_populates="user", uselist=False)
    counselor = relationship("Counselor", back_populates="user", uselist=False)
    sessions = relationship("Session", back_populates="user")